# 构建阶段：使用 JDK 17 构建应用
FROM eclipse-temurin:17-jdk-alpine AS builder

ENV SPRING_PROFILES_ACTIVE=online

LABEL maintainer="wdzgdh"

WORKDIR /workspace

# 安装 curl
RUN apk add --no-cache curl

# 安装 Maven
RUN apk add --no-cache curl tar && \
    MVN_VERSION=3.8.6 && \
    curl -fsSLo /tmp/apache-maven.tar.gz https://archive.apache.org/dist/maven/maven-3/$MVN_VERSION/binaries/apache-maven-$MVN_VERSION-bin.tar.gz && \
    mkdir -p /opt/maven && \
    tar -xzf /tmp/apache-maven.tar.gz -C /opt/maven --strip-components=1 && \
    ln -s /opt/maven/bin/mvn /usr/local/bin/mvn

COPY pom.xml .
COPY src ./src

RUN mvn -B clean package -DskipTests

# 运行阶段：使用 JRE 运行（更小体积）
FROM eclipse-temurin:17-jre-alpine

# 设置时区
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
ENV TZ=Asia/Shanghai

EXPOSE 8081

WORKDIR /app

COPY BlogSystem.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]
